<?php
switch($_POST["cmd"]) {
case "msi":
	switch($_POST["detail"]) {
	case "add":
		// add new task
		$data = "cmd=task_add\n";
		$network->send($data);
		while($from = $network->recv()) {
			if(strpos($from, "task_add_reply") !== false) {
				break;
			}
		}
		$pm->init($from, "|");
		$task_id = $pm->get("id");

		$network->send("cmd=task_set|id=$task_id|data=todo_count|value=1\n");
		$network->send("cmd=task_set|id=$task_id|data=block_size|value=1\n");
		$network->send("cmd=task_set|id=$task_id|data=timeout|value=30\n");
	
		$network->send("cmd=task_set|id=$task_id|data=db_user|value=dispatch\n");
		$network->send("cmd=task_set|id=$task_id|data=db_pass|value=dispatchpw\n");
		$network->send("cmd=task_set|id=$task_id|data=db_name|value=dispatch\n");
		$network->send("cmd=task_set|id=$task_id|data=db_host|value=tloyd-ser\n");
		$network->send("cmd=task_set|id=$task_id|data=db_port|value=3306\n");

		$network->send("cmd=task_set|id=$task_id|data=todo|value=msi\n");
		$network->send("cmd=task_set|id=$task_id|data=action|value=add\n");
		$network->send("cmd=task_set|id=$task_id|data=length|value=3\n");

		$network->send("cmd=task_start|id=$task_id\n");
		break;
	case "start":
		// add new task
		$data = "cmd=task_add\n";
		$network->send($data);
		while($from = $network->recv()) {
			if(strpos($from, "task_add_reply") !== false) {
				break;
			}
		}
		$pm->init($from, "|");
		$task_id = $pm->get("id");

		$network->send("cmd=task_set|id=$task_id|data=todo_count|value=1\n");
		$network->send("cmd=task_set|id=$task_id|data=block_size|value=1\n");
		$network->send("cmd=task_set|id=$task_id|data=timeout|value=30\n");
	
		$network->send("cmd=task_set|id=$task_id|data=db_user|value=dispatch\n");
		$network->send("cmd=task_set|id=$task_id|data=db_pass|value=dispatchpw\n");
		$network->send("cmd=task_set|id=$task_id|data=db_name|value=dispatch\n");
		$network->send("cmd=task_set|id=$task_id|data=db_host|value=tloyd-ser\n");
		$network->send("cmd=task_set|id=$task_id|data=db_port|value=3306\n");

		$network->send("cmd=task_set|id=$task_id|data=todo|value=msi\n");
		$network->send("cmd=task_set|id=$task_id|data=action|value=start\n");

		$network->send("cmd=task_start|id=$task_id\n");
		break;
/*	case "process":
		// add new task
		$data = "cmd=task_add\n";
		$network->send($data);
		while($from = $network->recv()) {
			if(strpos($from, "task_add_reply") !== false) {
				break;
			}
		}
		$pm->init($from, "|");
		$task_id = $pm->get("id");

		$network->send("cmd=task_set|id=$task_id|data=todo_count|value=1\n");
		$network->send("cmd=task_set|id=$task_id|data=block_size|value=1\n");
		$network->send("cmd=task_set|id=$task_id|data=timeout|value=30\n");
	
		$network->send("cmd=task_set|id=$task_id|data=db_user|value=dispatch\n");
		$network->send("cmd=task_set|id=$task_id|data=db_pass|value=dispatchpw\n");
		$network->send("cmd=task_set|id=$task_id|data=db_name|value=dispatch\n");
		$network->send("cmd=task_set|id=$task_id|data=db_host|value=tloyd-ser\n");
		$network->send("cmd=task_set|id=$task_id|data=db_port|value=3306\n");

		$network->send("cmd=task_set|id=$task_id|data=todo|value=msi\n");
		$network->send("cmd=task_set|id=$task_id|data=action|value=process\n");
		$network->send("cmd=task_set|id=$task_id|data=instance_id|value=1\n");

		$network->send("cmd=task_start|id=$task_id\n");
		break;
*/
	}
}
?>
